package com.xlro.service;

import com.xlro.dao.UserDao;
import com.xlro.domain.User;

import java.util.ArrayList;

public class UserService {

    UserDao userDao = new UserDao();
    public User getUser(String username) {
        User user = new User();
        for (User u:userDao.getAll()
             ) {
            if(u.getUsername().equals(username)){
                return u;
            }
        }
        return null;
    }

    public String getUserById(String id) {
//                "UPDATE borrow_card set borrow_card.username=\"2\" AND borrow_card.`describe`=\"\" and borrow_card.cellphone =\"\" and borrow_card.email = \"\" and borrow_card.sex = \"\" where id=\"16\""
        return id;
    }

    public String alterPass(String id,String pass) {
        return userDao.alterPass(id,pass)>0?"修改成功":"修改失败";
    }

    public String alterInfo(String id, String username, String reader, String desc, String cell, String email, String sex) {
        System.out.println(sex);
        return userDao.alterInfo(id,username,reader,desc,cell,email,sex)>0?"修改成功":"修改失败";
    }

    public ArrayList<User> getAll() {
        return userDao.getAll();
    }

    public String jinUser(String id) {
        return userDao.changeStatus(id)>0?"禁用成功":"禁用失败";
    }

    public String deleteOneUser(String id) {
        return userDao.deleteOne(id)>0?"删除成功":"删除失败";
    }
}
